All Questions
27 questions
8votes
3answers
2kviews
Is set of integers closed under the operation of subtraction?
I was working on a problem, but my solution did not pass the time limit test. Problem Let's say a set of integers is closed under the operation of subtraction if for two distinct elements of this set ...
6votes
1answer
347views
Codeforces: D2. Counting Is Fun (Hard Version)
The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
4votes
2answers
513views
Leetcode: Steps to Make Array Non-decreasing
I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
9votes
4answers
2kviews
Leetcode : First Missing Positive
I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
10votes
3answers
2kviews
Repeatedly remove a substring quickly
I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
2votes
2answers
98views
For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m
A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
1vote
1answer
233views
Find a secret word given an array of triplets? (codewars problem)
The rules for the puzzle are: Each triplet has the rules of how the letters are ordered in the secret word (each letter is followed by the next letter inside the triplet array). all the letters of ...
2votes
3answers
415views
Leetcode First Unique Character in a String code optimisation
I was working on First Unique Character in a String Question Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: ...
1vote
1answer
180views
Maximum Profit in Job Scheduling - Performance Issue
I implemented the Maximum Profit in Job Scheduling algorithm in JavaScript, but I'm having performance issue. The problem: We have n jobs, where every job is scheduled to be done from startTime[i] to ...
3votes
1answer
537views
Optimizing Dijkstra on grid Python (Microsoft Interview)
Given a square grid of size N, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which ...
2votes
1answer
3kviews
Dynamic Array Problem (Hacker rank)
I am trying to solve the Dynamic Array problem on HackerRank: Create a list, seqList, of N empty sequences, where each sequence is indexed from 0 to N-1. The elements within each of the N ...
2votes
2answers
169views
Designing a stack such that getMin() is both constant time and constant space
I'm attempting the SpecialStack problem on GeeksforGeeks. Design a data-structure SpecialStack (using the STL of stack) that supports all the stack operations like push(), pop(), isEmpty(), ...
5votes
1answer
2kviews
Count words with given prefix using Trie
I have been trying to solve this HackerRank problem: We're going to make our own Contacts application! The application must perform two types of operations: add name, where is a string denoting a ...
4votes
1answer
2kviews
CodeChef's Tree MEX (Minimum Excludant) challenge
This code is a solution for CodeChef's Tree MEX problem: Minimum excludant (or MEX for short) of a collection of integers is the smallest non-negative integer not present in the set. You ...
1vote
1answer
97views
Sum of number's quotients when divided by exact powers of 2
Problem I have written code to solve this challenge: Given a formula: GCD(x,y) means the GCD (Greatest Common Divisor) of x and y. For example: if N=2, then: f(2) = 1/GCD(1, 4) + 2/GCD(2, 4) + 3/...